package com.jc.camerascan.widget.mine;

import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.jc.camerascan.R;
import com.jc.camerascan.core.BaseActivity;
import com.jc.camerascan.entity.event.AliPayEvent;
import com.jc.camerascan.entity.event.WechatPayEvent;
import com.jc.camerascan.utils.XToastUtils;
import com.jc.camerascan.widget.BaseBottomDialog;
import com.xuexiang.xui.widget.button.SwitchIconView;
import com.xuexiang.xui.widget.textview.supertextview.SuperButton;

import org.greenrobot.eventbus.EventBus;

/**
 * @Package: com.jc.camerascan.widget.mine
 * @Description: java类作用描述
 * @Author: xuchi
 * @CreateDate: 2020/8/2 19:54
 * @Version: 1.0
 */
public class BottomPayTypeDialog extends BaseBottomDialog {

    private String priceStr;
    private Context context;
//    private int isFrom;

    public BottomPayTypeDialog(@NonNull Context context) {
        super(context);
    }

    public BottomPayTypeDialog(@NonNull Context context, String price) {
        super(context);
        this.priceStr = price;
        this.context = context;
    }

    public BottomPayTypeDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected BottomPayTypeDialog(@NonNull Context context, boolean cancelable, @Nullable DialogInterface.OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void setContentView(@NonNull View view) {
        super.setContentView(view);
    }

    private ImageView close;
    private TextView price;
    private SwitchIconView checkbox;
    private SwitchIconView checkboxTwo;
    private SuperButton pay;
    private RelativeLayout wechatPay;
    private RelativeLayout aliPay;

    @Override
    public void show() {
        super.show();
        close = mContentView.findViewById(R.id.close);
        price = mContentView.findViewById(R.id.price);
        pay = mContentView.findViewById(R.id.pay);
        price.setText(priceStr);
        pay.setText("确认支付（￥" + priceStr + "）");
        checkbox = mContentView.findViewById(R.id.checkbox);
        checkboxTwo = mContentView.findViewById(R.id.checkbox_two);
        wechatPay = mContentView.findViewById(R.id.wechat_pay);
        aliPay = mContentView.findViewById(R.id.ali_pay);
        checkbox.setIconEnabled(true);
        wechatPay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                checkbox.switchState();
                checkboxTwo.switchState();
            }
        });
        aliPay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                checkbox.switchState();
                checkboxTwo.switchState();
            }
        });
        pay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (checkbox.isIconEnabled() && !checkboxTwo.isIconEnabled()) {
                    EventBus.getDefault().post(new WechatPayEvent());
                    dismiss();
                } else if (!checkbox.isIconEnabled() && checkboxTwo.isIconEnabled()) {
                    EventBus.getDefault().post(new AliPayEvent());
                    dismiss();
                } else {
                    XToastUtils.warning("请选择一种支付方式");
                }
            }
        });
        close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
    }

    @Override
    public void dismiss() {
        super.dismiss();
    }
}

